#ifndef _MODELCLASS_H_
#define _MODELCLASS_H_


#include <d3d11.h>
#include <d3dx10math.h>
#include "material.h"

class ModelClass
{
private:
	struct VertexType
	{
		D3DXVECTOR3 position;
		D3DXVECTOR3 norm;
		D3DXVECTOR3 tan;
		D3DXVECTOR3 binorm;
		D3DXVECTOR2 tex;
	};

public:

	ModelClass(float pos_x = 0.0f, float pos_y = 0.0f, float pos_z = 0.0f, float scale_x = 1.0, float scale_y = 1.0 ,float scale_z = 1.0);

	bool Initialize(ID3D11Device*);
	void Shutdown();
	void Render(ID3D11DeviceContext*);
	int GetIndexCount();

	void SetMaterial(Material* const i_material)
	{
		m_material = i_material;
	}

	const Material* GetMaterial()
	{
		return m_material;
	}

	void SetPosition(float pos_x , float pos_y , float pos_z )
	{
		//D3DXMATRIX trasl;
		m_transformation._41 = pos_x;
		m_transformation._42 = pos_y;
		m_transformation._43 = pos_z;

		/*D3DXMatrixIdentity(&trasl);
		D3DXMatrixTranslation(&trasl,pos_x, pos_y, pos_z);
		D3DXMatrixMultiply(&m_transformation, &m_transformation, &trasl);*/


	};

	void SetScale(float s_x , float s_y , float s_z )
	{
		//D3DXMATRIX scale;
		m_transformation._11 = s_x;
		m_transformation._22 = s_y;
		m_transformation._33 = s_z;

		/*D3DXMatrixIdentity(&scale);
		D3DXMatrixScaling(&scale,s_x, s_y, s_z);
		D3DXMatrixMultiply(&m_transformation, &m_transformation, &scale);*/
	};

	const D3DMATRIX& GetTransformationMatrix() const
	{
		return m_transformation;
	};

private:
	bool InitializeBuffers(ID3D11Device*);
	void ShutdownBuffers();
	void RenderBuffers(ID3D11DeviceContext*);

	void ComputeTangentBasis(const D3DXVECTOR3& P1, const D3DXVECTOR3& P2, const D3DXVECTOR3& P3, 
							const D3DXVECTOR2& UV1, const D3DXVECTOR2& UV2, const D3DXVECTOR2& UV3,
							D3DXVECTOR3 &o_normal, D3DXVECTOR3 &o_tangent, D3DXVECTOR3 &o_bitangent );

private:

	ID3D11Buffer	*m_vertexBuffer, *m_indexBuffer;
	float			m_pos[3];
	float			m_scale[3];
	D3DXMATRIX		m_transformation;
	int				m_vertexCount, m_indexCount;
	Material*		m_material;
	
};

#endif